<?php
namespace app\api\controller;
use app\common\controller\Base;

/**
 * 服务模块  - 无需登录
 */
class ServicePub extends Base{
    protected $tn = 'common/service';


    /**
     * [serviceInfo 服务详情]
     * @return [type] [description]
     */
    public function serviceInfo(){
        $validate = new \think\validate(
            [
                'id' => 'require',
                'lng' => 'require',
                'lat' => 'require'
            ],[
                'id.require' => '参数id丢失',
                'lng.require' => '参数lng丢失',
                'lat.require' => '参数lat丢失'
            ]
        );
        if($validate->check($this->post) === false){
            $this->apiReturn(0,$validate->getError());
        }


        $info = model($this->tn)->getInfo(['s.id' => intval($this->post['id'])],trim($this->post['lng']),trim($this->post['lat']));

        if(is_null($info)){
            $this->apiReturn(0,'该需求不存在或已被删除');
        }

        $info['is_care'] = $info['is_collect'] = 0 ;
        //是否关注
        if(isset($this->post['token']) && trim($this->post['token'])){
            $this->user_check(trim($this->post['token']));
            if(db('user_care')->where('user_id',UID)->where('care_id',$info['user_id'])->find()){
                $info['is_care'] = 1 ;
            }
            if(db('collect')->where('type',3)->where('foreign_key',$info['id'])->where('user_id',UID)->find()){
                $info['is_collect'] = 1;
            }
        }   
        $this->apiReturn(1,'详情',$info);
    }

    //服务评价标签
    public function tag(){
        
    }
}
